
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="scripts/jquery-3.3.1.js"></script>
<title>购物主页</title>
</head>

<style>
.head{
	text-align: center;
	margin-top:20px;
	margin-bottom: 50px;
}
.content{
	margin: 0 auto;
	
}
.table{
text-align: center;
}
.table_center{
	display: inline-block;
}
#bookTable{
	margin-top:50px;
	border-right: 1px solid #000;
	border-bottom: 1px solid #000;
	border-collapse:collapse;	
}
#bookTable th{
	width:120px;
	height:30px;
	border-left: 1px solid #000;
	border-top: 1px solid #000;
	
}
#bookTable td{
	border-left: 1px solid #000;
	border-top: 1px solid #000;
}
</style>
<body>
<%String path=request.getContextPath(); %>
<div class="head">
<span>欢迎你${user.username}</span>
<a href="">退出</a>
<a href="<%=path%>/Cart">查看购物车</a>
<a href="<%=path%>/GetOrderServlet">查看订单</a>
<c:if test="${user.cart==null}"><a href="bound.jsp">绑定银行卡</a></c:if>
</div>
<div class="content">
	<div class="table">
	<div class="table_center">
	<!-- 价格区间：<input type="text"/>~<input type="text"/><input type="button" value="查询"/> -->
	<table id="bookTable" >
		<tr>
	        <th>序号</th>
	        <th>商品名</th>
	        <th>金额</th>
	        <th>操作</th>
	    </tr>
	    <c:forEach var="goods" items="${page.list}" varStatus="status">
	    <tr>
	    <td>${status.count} </td>
	    <td><img src="${goods.imgSrc}" style="width:100px;height=100px"><br>${goods.goods_name}</td>
	    <td>${goods.price}</td>
	    <td><input type="text" value="${goods.id}" style="display:none;"/><a href="#" onclick="addToCart(${goods.id})">加入购物车</a></td>
		</tr>
		</c:forEach>
	</table>
	<div>
		共有${page.totalRecord}个商品,共有${page.totalPage}页
		<br>
		<a href="<%=path%>/GetGoodsList?pageNum=1">首页</a>
		<c:if test="${page.pageNum==1}">
			<c:forEach begin="${page.start}" end="${page.end}" step="1" var="i">
				<c:if test="${page.pageNum==i}">
					${i}
				</c:if>
				<c:if test="${page.pageNum!=i}">
				<a href="<%=path%>/GetGoodsList?pageNum=${i}">${i}</a>
				</c:if>
			</c:forEach>
			<a href="<%=path%>/GetGoodsList?pageNum=${page.pageNum+1}">下一页</a>
		</c:if>
		<c:if test="${page.pageNum>1&&page.pageNum<page.totalPage}">
			<a href="<%=path%>/GetGoodsList?pageNum=${page.pageNum-1}">上一页</a>
			<c:forEach begin="${page.start}" end="${page.end}" step="1" var="i">
				
				<c:if test="${page.pageNum==i}">
					${i}
				</c:if>
				<c:if test="${page.pageNum!=i}">
					<a href="<%=path%>/GetGoodsList?pageNum=${i}">${1}</a>
				</c:if>
			</c:forEach>
			<a href="<%=path%>/GetGoodsList?pageNum=${page.pageNum+1}">下一页</a>
		</c:if>
		<c:if test="${page.pageNum==page.totalPage}">
			<a href="<%=path%>/GetGoodsList?pageNum=${page.pageNum-1}">上一页</a>
			<c:forEach begin="${page.start}" end="${page.end}" step="1" var="i">
				
				<c:if test="${page.pageNum==i}">
					${i}
				</c:if>
				<c:if test="${page.pageNum!=i}">
					<a href="<%=path%>/GetGoodsList?pageNum=${i}">${1}</a>
				</c:if>
			</c:forEach>
		</c:if>
	</div>
	</div>
	</div>
</div>
</body>
<script >
	function addToCart(id,a){
		$.get("AddToCart?goods_id="+id,function(data){
			if(data>0){
				alert("加入购物车成功");
			}else{
				alert("没有库存啦");
			}
		});
	}
	
</script>
</html>